class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showmodal: !1,
            showmodal1: !1,
            isandroid: !0,
        };
    }



    componentDidMount() {




        let userid = localStorage.getItem('userid1'), token = localStorage.getItem('token')


           if(userid=!null&&token!=null){
            window.location.href = './main.html'
           }




        //         new VConsole()
        //         let code = GetQueryString('code');
        //         if(code=='null'){
        //   let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd8d76eb5ff993f57&redirect_uri=http://chuanxingcloud.com/h5dish/index.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
        //           //  window.location.href=url
        //         }else{
        //             console.log(code,'codecode');
        //             wxlogin(code,res=>{
        //                 console.log('wxlogin',res);
        //                 localStorage.setItem('openid',res.data.openid)
        //             })
        //         }
    }

    inputchange(e) {
        this.setState({ phone: e.target.value })

    }
    cbchange(e) {
        //console.log('cbchange', e.target.checked);
        this.setState({ isagree: e.target.checked })
    }

    toxieyi(e) {
         window.location.href='./xieyi.html?t='+e
    }

    submit() {
        if (!this.state.isagree) {
            alert('请先勾选同意协议')
        } else {
            let { phone } = this.state, err = ''
            if (phone.length != 11) { err = '手机号输入有误' }
            if (err != '') {
                alert(err)
            } else {
                bind(phone, res => {
                    console.log(res, 'resres--bind');

                    if (res.issuccess == 1) {
                        localStorage.setItem('userid', res.userid)
                        localStorage.setItem('phone', phone)
                        localStorage.setItem('token', res.token)
                        this.setState({showmodal:!1,showmodal1:!0})
                        // window.location.href = './main.html'
                    } else {
                        alert(res.msg)
                    }
                })

            }

        }
    }









    render() {
        let { phone, showmodal, isagree, showmodal1 } = this.state;
        return (
            <div className="all">
                <div className="bg">
                    <img loading="lazy" src="./src/index_bg.png" alt="" />
                    <img style={{ display: showmodal1 ? 'none' : '' }} className="go" onClick={() => {
                        this.setState({ showmodal: !0 })
                    }} src="./src/index_btn1.png" alt="" />

                </div>
                <div style={{ display: showmodal ? '' : 'none' }} className="modal">
                    <div onClick={() => {
                        this.setState({ showmodal: !1 })
                    }} className="mask"></div>
                    <div className="content">
                        <p className="title">绑定手机号</p>
                        <div className="inputt">
                            <p>手机号</p>
                            <input type="text" maxLength={11} onChange={this.inputchange.bind(this)} value={phone} />

                        </div>
                        <div className="cb">
                            <input type="checkbox" onChange={this.cbchange.bind(this)} checked={isagree} />
                            <div>
                                <p>我已阅读并同意</p>
                                <p onClick={()=>{
                                    window.location.href='./hdsm.html'
                                }} className="blue">《活动说明》</p>
                                <p>以及</p>
                                <p onClick={this.toxieyi.bind(this, 'yszc')} className="blue">《隐私政策》</p>
                            </div>
                        </div>
                        <div onClick={this.submit.bind(this)} className="btns">
                            <img src="./src/index_btn.png" alt="" />
                        </div>

                    </div>
                </div>
                <div style={{ display: showmodal1 ? '' : 'none' }} className="modal1">
                    <div onClick={() => {
                      //  this.setState({ showmodal1: !1 })
                        window.location.href='./main.html'
                    }} className="mask"></div>

                    <img className="hdsm_word" src="./src/hdsm_word.png" alt="" />
                    <img src="./src/close.png" onClick={() => {
                       // this.setState({ showmodal1: !1 })
                       window.location.href='./main.html'
                    }}  className="close" alt="" />
                </div>

            </div>


        )
    }
}

ReactDOM.render(
    <div>
        {/* <TopLine /> */}
        <div id='body'>

            <Main />
        </div>
    </div>
    // <Barrage />
    , $('.container')[0]
)